"""
瑞数
"""
import requests
from DrissionPage import ChromiumOptions, WebPage

base_url = 'http://epub.cnipa.gov.cn/'
headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Referer": 'http://epub.cnipa.gov.cn/',
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
}


def gen_rs_cookie():
    dp = ChromiumOptions()
    # dp.no_imgs(True).mute(True)
    # dp.incognito()  # 匿名模式
    dp.headless()  # 无头模式
    # dp.set_argument('--no-sandbox')  # 无沙盒模式
    # dp.set_argument('--disable-gpu')  # 禁用gpu加速
    dp.set_argument('--start-maximized')  # 设置启动时最大化
    # dp.set_argument('--disable-blink-features=AutomationControlled')
    dp.set_user_agent(
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36')
    page = WebPage(mode='d', chromium_options=dp)
    page.get(base_url)
    try:
        cookies = page.cookies().as_dict()
        print(cookies)
    finally:
        page.quit()
    return cookies


def query():
    cookies = gen_rs_cookie()
    resp = requests.get(base_url, cookies=cookies, headers=headers)
    print('破解结果: {}'.format('成功' if resp.status_code == 200 else '失败'))


if __name__ == '__main__':
    query()
